<template>
<div>
  <el-row :gutter="25">
    <el-col :span="10">
      <!-- 搜索添加 -->
      <el-input placeholder="请输入搜索内容" v-model="queryInfo.query" clearable @clear="getBideList()">
        <el-button slot="append" icon="el-icon-search" @click="getBideList()"></el-button>
      </el-input>
    </el-col>
  </el-row>
  <el-table :data="bideList" border stripe>
    <el-table-column type="index"></el-table-column>
    <el-table-column label="工厂ID" prop="bid_fac_id"></el-table-column>
    <el-table-column label="订单ID" prop="bid_ord_id" width="100"></el-table-column>
    <el-table-column label="工厂名称" prop="bid_fac_name" width="100"></el-table-column>
    <el-table-column label="负责人" prop="bid_fac_conn" width="100"></el-table-column>
    <el-table-column label="联系电话" prop="bid_fac_tel" width="100"></el-table-column>
    <el-table-column label="报价" prop="bid_price"></el-table-column>
    <el-table-column label="标书状态" prop="bid_state"></el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <!--选标-->
        <el-button type="primary" icon="el-icon-check" @click="hitOrder(scope.row.bid_fac_id)" circle></el-button>
      </template>
    </el-table-column>
  </el-table>
</div>
</template>

<script>
export default {
  data(){
    return{
      ord_id:'',
      fac_id:'',
      bideList:[],
      queryInfo: {
        query: "",
        pageNum: 1,
        pageSize: 5,
        fac :'',
        ord:'',
      },
    }
  },
  created() {
    this.getTempOrdId();
    this.getTempFacId();
    this.getBideList();
  },
  methods:{
    async getBideList(){
      // 调用post请求
      this.queryInfo.fac = this.fac_id;
      this.queryInfo.ord = this.ord_id;
      const { data: res } = await this.$http.get("order/bideList", {
        params: this.queryInfo
      });
      for(var i in res.data){
        if(res.data[i].bid_state === 0){
          res.data[i].bid_state = '未中标';
        }
      }
      this.bideList= res.data; // 将返回数据赋值
      //使用for循环更新对应的变量
      this.total = res.numbers; // 总个数
    },
    getTempFacId(){
      this.fac_id = window.sessionStorage.getItem("fac_id");
    },
    getTempOrdId(){
      this.ord_id = window.sessionStorage.getItem("ord_id");
    },
    async hitOrder(id){
      // 调用post请求
      this.queryInfo.fac = id;
      this.queryInfo.ord = this.ord_id;
      const { data: res } = await this.$http.get("order/hitOrder", {
        params: this.queryInfo
      });
      if(res === 'success'){
        this.$message.success("中标成功");
        this.$router.push("/orderList");
      }else{
        this.$message.error("中标失败");
      }
    }
  }
}
</script>

<style scoped>

</style>